<include file="Public/popHeader"/>
<body class="hold-transition skin-blue sidebar-mini">
<!-- 内容页 -->
<div class="">
    <!-- 内容 -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title"></h3>
                        <div class="form-inline pull-right">
                            <form action="" method="get">
                                <fieldset>
                                    <div class="input-group input-group-sm">
                                        <span class="input-group-addon"><strong>货品名称</strong></span>
                                        <input type="text" class="form-control" placeholder="货品名称" name="name" value="">
                                    </div>

                                    <div class="input-group input-group-sm">
                                        <div class="input-group-btn">
                                            <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i>
                                            </button>
                                        </div>
                                    </div>

                                </fieldset>
                            </form>
                        </div>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <tbody>
                            <tr>
                                <th><input type="checkbox" class="grid-select-all"></th>
                                <th>ID</th>
                                <th>货品名称</th>
                                <th>图片</th>
                                <th>货品描述</th>
                                <th>市场价</th>
                                <th>销售价</th>
                                <th>库存</th>
                                <th>折后价</th>
                                <th>冻结库存</th>
                            </tr>
                            <foreach name="product_relation_msg" item="v">
                                <tr class="cg-product-tr">
                                    <td><input type="checkbox" class="grid-item" data-id="{$v.store_pid}"data-marketprice="{$v.marketprice}" data-price="{$v.price}" data-info="{$v.spec_info}" data-name="{$v.name}"></td>
                                    <td>{$v.store_pid}</td>
                                    <td>{$v.name}</td>
                                    <td><img class="scale-img" src="{:getThumb($v['goods_id'])}" data-bimg="{:getThumb($v['goods_id'])}"/></td>
                                    <td>{$v.spec_info}</td>
                                    <td>{$v.marketprice}</td>
                                    <td>{$v.price}</td>
                                    <td>{$v.store}</td>
                                    <td>{$v.discount}</td>
                                    <td>{$v.freez}</td>
                                </tr>
                            </foreach>
                            </tbody>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        <input type="checkbox" class="grid-select-all">&nbsp;&nbsp;&nbsp;
                        <a class="btn btn-sm btn-info add-goods">保存</a>
                        {$show}
                    </div>
                    <!-- /.box-body -->
                </div>
            </div>
        </div>

    </section>
</div>
</body>
<script>
    $(function () {		
        var chids = parent.$("#yc-goods-ids").val();
        var ychser = new YcChoser();
        ychser.setChosenIds(chids);

        $(".grid-item").each(function(){
            if(ychser.isRepeat($(this).attr("data-id"))){
                $(this).prop("checked", "checked");
            }
        });

        $('.grid-select-all').change(function () {
            if (this.checked) {
                $('.grid-item').prop("checked", true);
            } else {
                $('.grid-item').prop("checked", false);
            }
        });

        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引

        $('.add-goods').on('click', function () {
            $('.grid-item').each(function () {
                var id = $(this).data('id'); // id
                var name = $(this).data('name'); // 商品名称
                var info = $(this).data('info'); // 商品规格
                var price = $(this).data('price'); // 商品售价

                var flag = ychser.isRepeat($(this).attr("data-id"));
                if(flag && !$(this).is(':checked')){
                    ychser.remove();
                    parent.$('.ui-sortable').children("li").eq(ychser.getPosition()).remove();
                }else if ($(this).is(':checked') && !flag) {
                    ychser.add($(this).attr("data-id"));
                    var html = '';
                    html += '<li>';
                    html += '<input type="hidden" name="goods_id[]" value="'+id+'">';
                    html += '<a href="javascript:;" title="'+(name + info)+'" class="text ebatch-name"> '+name+ info+'</a>';
                    html += '<input type="hidden"  name="current_price[]" value="'+price+'"/>';
                    html += '<div class="tools">';
                    html += '<i class="fa fa-trash-o icondel" data-id="'+id+'" onclick="delGoodsItem(this)"></i>';
                    html += '</div>';
                    html += '</li>';
                    parent.$('.ui-sortable').append(html);
                }
            });
            parent.updateGoodsIds(ychser.getChosenIds());
            parent.layer.close(index);
        });

    });
	
	showBigPicture();
</script>

